package src.zhuzi.spring.ioc.base;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;

import org.springframework.context.annotation.Bean;


public class Base {
	public Base(){
		try{
			Method[] ms = this.getClass().getMethods();
			Properties prop = new Properties();
			prop.load(Bean.class.getClassLoader().getResourceAsStream("system.properties"));
			for(Method m:ms){
				if(m.isAnnotationPresent(Inject.class)){
					String mname = m.getName();//setWeapon
					mname = mname.substring(3);
					mname = mname.substring(0,1).toLowerCase()+mname.substring(1);
					String cname = prop.getProperty(mname);
					Object o = Class.forName(cname).newInstance();
					m.invoke(this,o);
				}
			}
		}catch (IOException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
	}
}